/*
 * @Author: your name
 * @Date: 2022-02-20 20:45:16
 */
const { mock } = require('mockjs')

const List = []
const count = 20
for (let i = 0; i < count; i++) {
  List.push(
    mock({
      id: '@id',
      title: '@title(1, 2)',
      description: '@sentence(1, 6)',
      datetime: '@datetime()',
      img: `https://gitee.com/topreventalife/source/raw/img/images/c${
        i + 1
      }.jpg`,
    })
  )
}

module.exports = [
  {
    url: '/card/getList',
    type: 'get',
    response(config) {
      if (!config.body) {
        return {
          code: 200,
          msg: 'success',
          totalCount: count,
          data: List,
        }
      }
      const { title = '', pageNo = 1, pageSize = 20 } = config.body
      let mockList = List.filter((item) => {
        return !(title && item.title.indexOf(title) < 0)
      })
      const pageList = mockList.filter(
        (item, index) =>
          index < pageSize * pageNo && index >= pageSize * (pageNo - 1)
      )
      return {
        code: 200,
        msg: 'success',
        totalCount: count,
        data: pageList,
      }
    },
  },
]
